package com.jt.consumer.service.fallback;

import com.jt.consumer.service.RemoteProviderService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 远程服务调用工程，当远端服务不可用时,可以
 * 通过此工厂创建一个service对象，返回一些友好信息
 */
@Component
public class ProviderFallbackFactory implements FallbackFactory<RemoteProviderService> {
    @Override
    public RemoteProviderService create(Throwable throwable) {
        /*return new RemoteProviderService() {
            @Override
            public String echoMessage(String msg) {
                return "服务忙，稍等片刻再访问";
            }
        };*/

        // jdk8中lambda表达式
        return (msg) -> "服务忙,稍等片刻再访问";
    }
}
